﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using LuaInterface;

namespace GaugeEngine.Scripting
{
    public class ScriptManager : GameComponent, IDisposable
    {
        private Lua m_luaState;
        public Lua LuaState
        {
            get { return m_luaState; }
        }

        public ScriptManager(Game g) : base(g)
        {
            m_luaState = new Lua();
        }

        public void registerFunction(string name, object reference)
        {
            Type pPrgType = reference.GetType();
            System.Reflection.MethodInfo info = pPrgType.GetMethod(name);
            m_luaState.RegisterFunction(name, reference, info);
        }

        public void RunScript(string filename)
        {
            m_luaState.DoFile(filename);
        }

        public void Dispose()
        {
            m_luaState.Dispose();
        }
    }
}
